package com.jinshan.statistics.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jinshan.response.RetVal;
import com.jinshan.statistics.entity.DailyStatistics;
import com.jinshan.statistics.mapper.DailyStatisticsMapper;
import com.jinshan.statistics.service.DailyStatisticsService;
import com.jinshan.statistics.service.UserServiceFeign;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 网站统计日数据 服务实现类
 * </p>
 *
 * @author Jinshan
 * @since 2020-06-30
 */
@Service
public class DailyStatisticsServiceImpl extends ServiceImpl<DailyStatisticsMapper, DailyStatistics> implements DailyStatisticsService {
    @Autowired
    private UserServiceFeign userServiceFeign;

    @Override
    public void generateStatistic(String date) {
        RetVal retVal = userServiceFeign.getRegisteredNum(date);
        Integer registeredNum = (Integer) retVal.getData().get("registeredNum");
        DailyStatistics statistics = new DailyStatistics();
        statistics.setDateCalculated(date);
        statistics.setRegisterNum(registeredNum);
        statistics.setCourseNum(RandomUtils.nextInt(200, 400));
        statistics.setLoginNum(RandomUtils.nextInt(200, 400));
        statistics.setVideoViewNum(RandomUtils.nextInt(200, 400));

        baseMapper.insert(statistics);
    }
}
